package com.hmall.api.FallbackFactory;

import com.hmall.api.ItemClient;
import com.hmall.api.dto.ItemDTO;
import com.hmall.api.dto.OrderDetailDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Slf4j
public class ItemFallbackFactory implements FallbackFactory<ItemClient> {

    @Override
    public ItemClient create(Throwable cause) {
        log.error(cause.getMessage(),cause);
       return new ItemClient() {


           @Override
           public List<ItemDTO> queryItemByIds(Collection<Long> ids) {
               log.info("ItemFallbackFactory 调用商品服务降级");
               return new ArrayList<>();
           }

           @Override
           public void deductStock(List<OrderDetailDTO> items) {
               throw new RuntimeException("库存扣减失败");
           }
       };
    }
}
